package com.example.springmvcdemo4.Controller;

import com.example.springmvcdemo4.model.Student;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/request")
public class RequestController {
    //接收单个参数
    @RequestMapping("/r1")
    public String r1(String name){
        return "name"+name;
    }
    //接收两个参数
    @RequestMapping("/r2")
    public String r2(String name,Integer age){
        return "name:"+name+"age:"+age;
    }
    //接收参数映射（参数重命名）
    @RequestMapping("/r3")
    public String r3(@RequestParam("name")String userName){
        return "userName"+userName;
    }
    //传入对象
    @RequestMapping("/r4")
    public String r4(Student student){
        return student.toString();
    }
    //传入数组
    @RequestMapping("/r5")
    public String r5(String[] arr){
        return Arrays.toString(arr);
    }
    //传入集合
    @RequestMapping("/r6")
    public List<Integer> r6(@RequestParam List<Integer> list){
        return list;
    }
    //传入json字符串
    @RequestMapping("/r7")
    public String r7(@RequestBody Student student){
        return student.toString();
    }
    //传入url中的数据
    @RequestMapping("/r8/{name}/{age}")
    public String r8(@PathVariable("name")String userName,@PathVariable Integer age){
        return "userName:"+userName+"age:"+age;
    }
    //传入文件
    @RequestMapping("/r9")
    public String r9(MultipartFile file){
        return file.getOriginalFilename();
    }
}
